home *** CD-ROM | disk | FTP | other *** search
- ; /*
- CatComp Reboot.cd CFILE Reboot_strings.h NOARRAY NOBLOCK NOCODE
- CatComp Reboot.cd CTFILE Reboot_blank.ct
- CatComp Reboot.cd Reboot_deutsch.ct CATALOG Catalogs/Deutsch/Reboot.catalog
-
- ; DICE
- dcc Reboot.c -mS -mi -proto -v -oReboot
-
- ; SAS
- ; SC RESOPT PARM=REGISTERS UCHAR CONSTLIB STREQ ANSI NOSTKCHK NOICONS OPT OPTPEEP Reboot.c
- ; Slink LIB:c.o Reboot.o TO Reboot LIB LIB:sc.lib SC SD
- Quit
- */
-
- /*
- **
- ** $VER: Reboot.c 1.1 (17.9.95)
- ** Reboot 1.0
- **
- ** main file
- **
- ** (C) Copyright 1994/1995 by Roland 'Gizzy' Mainz
- ** All Rights Reserved
- **
- */
-
- /* We did not want any names before V36 */
- #define INTUI_V36_NAMES_ONLY TRUE
-
- /* amiga includes */
- #include <exec/types.h>
- #include <utility/utility.h>
- #include <dos/dos.h>
- #include <intuition/intuition.h>
- #include <workbench/startup.h>
- #include <workbench/icon.h>
- #include <libraries/locale.h>
-
- /* amiga prototypes */
- #include <clib/exec_protos.h>
- #include <clib/utility_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/icon_protos.h>
- #include <clib/locale_protos.h>
-
- /* ansi includes */
- #include <string.h>
-
- /* version string */
- #include "Reboot_rev.h"
-
- /* locale */
- #define CATCOMP_NUMBERS
- #define CATCOMP_STRINGS
- #include "Reboot_strings.h"
-
- /* misc defines */
- #define NAME "Reboot"
-
- /* prototypes */
- void chkabort( void );
- long wbmain( struct WBStartup * );
- long main( long, STRPTR * );
- static void DefaultSettings( void );
- static void FreeInitProjectResult( void );
-
- static void ClearRDA( void );
- static void ScanRDA( void );
- static void ScanToolTypes( STRPTR * );
-
- static void RunTool( void );
- static BOOL OpenLibStuff( void );
- static void CloseLibStuff( void );
- static BOOL CreateBasicResources( void );
- static void DeleteBasicResources( void );
- void AttemptOpenLibrary( struct Library **, STRPTR, STRPTR, ULONG );
- static void RunTool( void );
- static void MyReboot( void );
- STRPTR SafeGetCatalogStr( struct Catalog *, LONG, STRPTR );
-
-
-
- /* version_string */
- STRPTR versionstring = VERSTAG;
-
- long main_retval,
- main_retval2;
-
- static struct RDArgs *startuprda;
-
- /* shared libraries */
- struct Library *UtilityBase,
- *IntuitionBase,
- *IconBase,
- *LocaleBase;
-
- /* locale support */
- struct Catalog *ct;
-
- /* template for ReadArgs() */
- #define STARTUP_TEMPLATE "REBOOTDELAY/K/N,QUIET=NOREQ/S"
-
- static
- struct
- {
- long *rebootdelay;
- long *noreq;
- } result;
-
- static
- struct
- {
- ULONG rebootdelay;
- ULONG noreq;
- } project;
-
-
- /* disable CTRL_C break support (DICE CTRL_C abort function) */
- void chkabort( void )
- {
- }
-
-
- long wbmain( struct WBStartup *wbstartup )
- {
- return( main( 0L, (STRPTR *)wbstartup ) );
- }
-
-
- long main( long ac, STRPTR *av )
- {
- LONG numArgs,
- x;
- struct WBStartup *wbstartup;
- struct WBArg *wbarg;
- struct DiskObject *tooldobj,
- *projectdobj;
- BPTR oldToolLock,
- oldProjectLock;
-
- x = main_retval2 = 0L;
- main_retval = RETURN_OK;
-
- DefaultSettings();
-
- /* Workbench */
- if( ac == 0L )
- {
- wbstartup = (struct WBStartup *)av;
-
- if( CreateBasicResources() )
- {
- numArgs = wbstartup -> sm_NumArgs;
- wbarg = wbstartup -> sm_ArgList;
-
- if( *(wbarg[ 0 ] . wa_Name) )
- {
- if( wbarg[ 0 ] . wa_Lock )
- {
- oldToolLock = CurrentDir( (wbarg[ 0 ] . wa_Lock) );
- }
-
- if( tooldobj = GetDiskObjectNew( (wbarg[ 0 ] . wa_Name) ) )
- {
- /* two possible cases when started from workbench ... */
- if( numArgs < 2L )
- {
- /* ... first case, only our tool icon is given, create one project here */
-
- ScanToolTypes( (STRPTR *)(tooldobj -> do_ToolTypes) );
-
- RunTool();
-
- FreeInitProjectResult();
- }
- else
- {
- /* ... second case, a couple of project icons are given, multiple projects will start from here */
- for( x = 1L ; x < numArgs ; x++ )
- {
- if( wbarg[ x ] . wa_Lock )
- {
- oldProjectLock = CurrentDir( (wbarg[ x ] . wa_Lock) );
- }
-
- if( *(wbarg[ x ] . wa_Name) )
- {
- if( projectdobj = GetDiskObject( (wbarg[ x ] . wa_Name) ) )
- {
- ScanToolTypes( (STRPTR *)(tooldobj -> do_ToolTypes) );
- ScanToolTypes( (STRPTR *)(projectdobj -> do_ToolTypes) );
-
- RunTool();
-
- FreeInitProjectResult();
- DefaultSettings();
-
- FreeDiskObject( projectdobj );
- }
- }
-
- if( wbarg[ x ] . wa_Lock )
- {
- CurrentDir( oldProjectLock );
- }
- }
- }
-
- FreeDiskObject( tooldobj );
- }
-
- if( wbarg[ 0 ] . wa_Lock )
- {
- CurrentDir( oldToolLock );
- }
- }
-
- DeleteBasicResources();
- }
- }
- else
- {
- /* CLI/Shell */
- if( CreateBasicResources() )
- {
- if( startuprda = ReadArgs( STARTUP_TEMPLATE, (LONG *)(&result), NULL ) )
- {
- /* did we get a CTRL_C signal ? */
- if( !CheckSignal( SIGBREAKF_CTRL_C ) )
- {
- ScanRDA();
-
- RunTool();
-
- FreeInitProjectResult();
- }
- else
- {
- main_retval2 = ERROR_BREAK;
- main_retval = RETURN_WARN;
- }
-
- FreeArgs( startuprda );
- }
- else
- {
- main_retval2 = IoErr();
- main_retval = RETURN_ERROR;
- }
-
- PrintFault( main_retval2, NAME );
-
- DeleteBasicResources();
- }
- }
-
- SetIoErr( main_retval2 );
-
- return( main_retval );
- }
-
-
- void DefaultSettings( void )
- {
- ClearRDA();
-
- memset( (&project), 0, sizeof(project) );
-
- project . rebootdelay = 2UL;
- }
-
-
- void ClearRDA( void )
- {
- memset( (&result), 0, sizeof(result) );
- }
-
-
- void ScanRDA( void )
- {
- if( result . rebootdelay )
- {
- project . rebootdelay = (ULONG)(*(result . rebootdelay));
- }
-
- project . noreq = result . noreq;
-
- ClearRDA();
- }
-
-
- void ScanToolTypes( STRPTR *tt )
- {
- STRPTR s;
-
- if( s = FindToolType( tt, "REBOOTDELAY" ) )
- (void)StrToLong( s, (LONG *)(&(project . rebootdelay)) ); /* note: result ignored */
-
- if( s = FindToolType( tt, "NOREQ" ) )
- result . noreq = (long *)s;
-
- if( s = FindToolType( tt, "QUIET" ) )
- result . noreq = (long *)s;
-
- ScanRDA();
- }
-
- static
- void FreeInitProjectResult( void )
- {
- /* NOP */
- }
-
-
- BOOL CreateBasicResources( void )
- {
- return( OpenLibStuff() );
- }
-
-
- void DeleteBasicResources( void )
- {
- CloseLibStuff();
- }
-
-
- BOOL OpenLibStuff( void )
- {
- if( IntuitionBase = OpenLibrary( "intuition.library", 37UL ) )
- {
- AttemptOpenLibrary( (&UtilityBase), NAME, UTILITYNAME, 37UL );
- AttemptOpenLibrary( (&IconBase), NAME, ICONNAME, 37UL );
- AttemptOpenLibrary( (&LocaleBase), NAME, "locale.library", 38UL );
-
- if( LocaleBase )
- {
- ct = OpenCatalogA( NULL, "Reboot.catalog", NULL );
- }
-
- if( IconBase )
- {
- return( TRUE );
- }
- }
-
- CloseLibStuff();
-
- return( FALSE );
- }
-
-
- void CloseLibStuff( void )
- {
- if( LocaleBase )
- {
- CloseCatalog( ct );
-
- CloseLibrary( LocaleBase );
- }
-
- CloseLibrary( IconBase );
- CloseLibrary( UtilityBase );
- CloseLibrary( IntuitionBase );
- }
-
-
- void AttemptOpenLibrary( struct Library **library, STRPTR title, STRPTR libname, ULONG libversion )
- {
- struct EasyStruct LibNotFoundES =
- {
- sizeof(struct EasyStruct),
- 0,
- title,
- SafeGetCatalogStr( ct, MSG_LIB_NOT_FOUND_REQTEXT, MSG_LIB_NOT_FOUND_REQTEXT_STR ),
- SafeGetCatalogStr( ct, MSG_LIB_NOT_FOUND_REQGAD, MSG_LIB_NOT_FOUND_REQGAD_STR )
- };
-
- struct EasyStruct LibWrongVersionES =
- {
- sizeof(struct EasyStruct),
- 0,
- title,
- SafeGetCatalogStr( ct, MSG_LIB_WRONG_VERSION_REQTEXT, MSG_LIB_WRONG_VERSION_REQTEXT_STR ),
- SafeGetCatalogStr( ct, MSG_LIB_WRONG_VERSION_REQGAD, MSG_LIB_WRONG_VERSION_REQGAD_STR )
- };
-
- if( (*library) == NULL )
- {
- for( ;; )
- {
- /* attemp to open shared library */
- (*library) = OpenLibrary( libname, 0UL );
-
- if( *library )
- {
- if( ((*library) -> lib_Version) < libversion )
- {
- EasyRequest( NULL, (&LibWrongVersionES), NULL, libname, libversion );
-
- CloseLibrary( (*library) );
- (*library) = NULL;
- }
-
- break;
- }
-
- /* prompt the user */
- if( EasyRequest( NULL, (&LibNotFoundES), NULL, libname ) == 0L )
- {
- /* user canceled */
- break;
- }
- }
- }
- }
-
-
- void RunTool( void )
- {
- struct EasyStruct RebootES =
- {
- sizeof(struct EasyStruct),
- 0,
- NAME,
- SafeGetCatalogStr( ct, MSG_REBOOT_REQTEXT, MSG_REBOOT_REQTEXT_STR ),
- SafeGetCatalogStr( ct, MSG_REBOOT_REQGAD, MSG_REBOOT_REQGAD_STR )
- };
-
- if( project . noreq )
- {
- MyReboot();
- }
- else
- {
- if( EasyRequest( NULL, (&RebootES), NULL ) == 1L )
- {
- /* user wants to reboot */
- MyReboot();
- }
- else
- {
- main_retval2 = ERROR_BREAK;
- main_retval = RETURN_WARN;
- }
- }
- }
-
-
- void MyReboot( void )
- {
- struct Window *abortreqwindow;
- ULONG x;
- BOOL abort;
- ULONG abortreqsignal,
- sigmask,
- signals;
-
- abort = FALSE;
-
- struct EasyStruct AbortRebootES =
- {
- sizeof(struct EasyStruct),
- 0,
- NAME,
- SafeGetCatalogStr( ct, MSG_ABORTREBOOT_REQTEXT, MSG_ABORTREBOOT_REQTEXT_STR )
- SafeGetCatalogStr( ct, MSG_ABORTREBOOT_REQGAD, MSG_ABORTREBOOT_REQGAD_STR )
- };
-
- if( (project . rebootdelay) < 1UL )
- {
- project . rebootdelay = 1UL;
- }
-
- if( project . noreq )
- {
- abortreqwindow = NULL;
- }
- else
- {
- abortreqwindow = BuildEasyRequestArgs( NULL, (&AbortRebootES), 0UL, NULL );
- }
-
- abortreqsignal = ((abortreqwindow)?(1UL << abortreqwindow -> UserPort -> mp_SigBit):(0UL));
-
- sigmask = SIGBREAKF_CTRL_C | abortreqsignal;
-
- /* For each second we'll check if any abort signal arrived (CTRL_C or requester) */
- for( x = 0UL ; (x < (project . rebootdelay)) ; x++ )
- {
- /* check if user aborts countdown */
- signals = CheckSignal( sigmask );
-
- if( signals & SIGBREAKF_CTRL_C )
- {
- abort = TRUE;
- }
-
- /* no window, no signal, no event processing ... */
- if( abortreqsignal )
- {
- if( signals & abortreqsignal )
- {
- if( SysReqHandler( abortreqwindow, NULL, FALSE ) == 0L )
- {
- abort = TRUE;
- }
- }
- }
-
- if( abort )
- {
- break;
- }
-
- Delay( TICKS_PER_SECOND );
- }
-
- /* Check if user has selected test mode ("Setenv Reboot OFF")*/
- if( abort == FALSE )
- {
- TEXT buff[ 256 ];
-
- if( GetVar( NAME, buff, 255L, 0UL ) != (-1L) )
- {
- /* may be replaced by ReadArgs() */
- if( !Stricmp( buff, "OFF" ) )
- {
- abort = TRUE;
- }
- }
- }
-
- if( abort )
- {
- main_retval2 = ERROR_BREAK;
- main_retval = RETURN_WARN;
- }
- else
- {
- /* bite in the dust */
- ColdReboot();
- }
-
- /* user has aborted the rebooting sequence */
- FreeSysRequest( abortreqwindow );
- }
-
-
- STRPTR SafeGetCatalogStr( struct Catalog *ct, LONG id, STRPTR s )
- {
- if( LocaleBase )
- {
- s = GetCatalogStr( ct, id, s );
- }
-
- return( s );
- }
-
-